from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column, relationship
from sqlalchemy import Integer, String, ForeignKey
from ..database.db import Base
from sqlalchemy import Column, Integer, String, DateTime, SmallInteger, PrimaryKeyConstraint
from datetime import datetime

class Textbook(Base):
    __tablename__='textbook'

    id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
    name: Mapped[str] = mapped_column(String(255))
    path: Mapped[str] = mapped_column(String(255))
    # type: # Mapped[str] = mapped_column(String(50))
    # type_id: Mapped[int] = mapped_column(Integer, ForeignKey('sources.id'))
    type: Mapped[str]=mapped_column(String(255))
    subject: Mapped[str] = mapped_column(String(255))
    grade: Mapped[str] = mapped_column(String(255))
    cover: Mapped[str] = mapped_column(String(255))
    starts: Mapped[int] = mapped_column(Integer)
    oss_url:Mapped[str]=mapped_column(String(255))
    # source = relationship("Sources", back_populates="textbooks")

    def as_dict(self):
        return {c.name: getattr(self, c.name) for c in self.__table__.columns}

